package com.JFapp.annotation.validator;

import com.JFapp.annotation.validator.name.IsPhone;
import com.alibaba.excel.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class IsPhoneValidator implements ConstraintValidator<IsPhone,String> {
    private static final Pattern PATTERN=Pattern.compile( "^1[345678]\\d{9}$");
    @Override
    public boolean isValid(String phone, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(phone)) {
            return true;
        }
        return PATTERN.matcher(phone).matches();
    }
}
